import request from '@/utils/request'



export function saveForm(data) {
    return request({
        url: "/api/forms/save",
        method: "post",
        headers: {
            "Content-Type": "application/json;charset=UTF-8"
        },
        data: JSON.stringify(data)  // 确保数据被正确地转换为JSON字符串
    });
}


export function getFormList(id) {
    return request({
        url: `/api/forms/list/${id}`,
        method: "get"
    });
}


export function submitForm(data) {
    return request({
        url: '/api/forms/submit',
        method: 'post',
        data
    });
}
export function getFormDetail(id) {
    return request({
        url: `/api/forms/detail/${id}`,
        method: 'get'
    });
}
// 分页获取表单列表
export function getPagedFormList(page, size) {
    return request({
        url: `/api/forms/listPaged`,
        method: 'get',
        params: { page, size }
    });
}
export function updateFormName(id, newName) {
    return request({
        url: `/api/forms/rename/${id}`,
        method: 'put',
        params: { newName }
    });
}
export function deleteForm(id) {
    return request({
        url: `/api/forms/delete/${id}`,
        method: 'delete'
    });
}


// 添加新的接口函数
export function addMember(spaceId, userId) {
    return request({
        url: `/api/forms/addMember/${spaceId}`,
        method: 'post',
        params: { userId }
    });
}

// 查询某个空间里面的全部成员
export function listMembers(spaceId) {
    return request({
        url: `/api/forms/listMembers/${spaceId}`,
        method: 'get'
    });
}
// 删除某个空间里面的某个成员
export function deleteMember(spaceId, userId) {
    return request({
        url: `/api/forms/deleteMember/${spaceId}`,
        method: 'delete',
        params: { userId }
    });
}
/**
 * 更改成员角色
 */
export function updateMemberRole(spaceId, userId, role) {
    return request({
        url: `/api/forms/updateMemberRole/${spaceId}`,
        method: 'put',
        params: { userId, role }
    });
}
